<script setup>
import {ref} from "vue";

const refTitle = ref("")
const refText = ref("")
const isShow = ref(false)

const showMessage = (title, text, delay) => {
  refTitle.value = title
  refText.value = text
  isShow.value = true
  console.log(refText.value)
  setTimeout(() => {isShow.value = false}, delay )
}

defineExpose({
  showMessage,
})

</script>

<template>
  <transition name="transitionMessage">
    <div class="message" v-show="isShow">
      <span class="message-title">{{ refTitle }}</span>
      <span class="message-text">{{ refText }}</span>
    </div>
  </transition>
</template>

<style scoped>
  .message {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: #2c3e50;
    border: #42b883 4px solid;
    border-radius: 16px;
    position: absolute;
    right: 20px;
    top: 70px;
    transition: all .5s;

  }

  .message-title {
    color: white;
    font-size: 18px;
  }

  .transitionMessage-enter-active, .transitionMessage-leave-active {
    transition: all .5s;
  }

  .transitionMessage-enter-from, .transitionMessage-leave-to {
    opacity: 0;
  }

  .transitionMessage-enter-to, .transitionMessage-leave-from {
    opacity: 1;
  }
</style>